<?php
//dump($data);

function state($cpt) {
    $now = date();
    if ($now < strtotime($cpt['start_time'])) {
        return '未开始';
    } else if ($now < strtotime($cpt['end_time'])) {
        return '进行中';
    } else {
        return '已结束';
    }
}
?>
<!DOCTYPE html>
<html lang="zhcn">
<head>
    <include file="Common/meta" />
    <title>我的竞赛 - {$_ENV['site'][0]['title']}</title>
    <include file="Common/link" />
</head>
<body>
<div class="layout-header">
    <div class="container">
        <h1 class="title">我的竞赛</h1>
        <a class="header-back" href="/user/personCenter"><i class="icon icon-left"></i></a>
    </div>
</div>
<include file="Common/header" />
<div class="container container-main">
            <?php
            //dump($data);
            ?>
            <if condition="count($data['list']) eq 0">
                <div id="search-empty" class="content-empty show">
                    <div class="picture"></div>
                    <div class="no-data">
                        没有竞赛，<a href="/competition/listPage">去参加竞赛</a>
                    </div>
                </div>
            </if>

            <ul class="user-cpt-list">
                <foreach name="data['list']" item="cpt">
                    <li class="cpt-item">
                        <a class="cpt-title" href="/competition/detail?id={$cpt['cpt_id']}">{$cpt['title']}</a>

                        <if condition="$cpt['join_status'] eq '0'">
                            <span class="cpt-state">[ 待审核 ]</span>
                        <elseif condition="$cpt['join_status'] eq '2'" />
                            <span class="cpt-state">[ 未通过审核 ]</span>
                        <else />
                            <span class="cpt-state">[ {$cpt|state} ]</span>
                        </if>
                        <div class="cpt-time">
                            比赛时间： {$cpt['start_time']|strtotime|date="Y.m.d",###} - {$cpt['end_time']|strtotime|date="Y.m.d",###}
                            &nbsp;&nbsp;&nbsp;&nbsp;报名时间： {$cpt['join_time']|strtotime|date="Y-m-d H:i",###}
                        </div>

                        <div class="operate">
                            <a class="cancel-join" href="" data-id="{$cpt['join_id']}">取消报名</a>
                            <notempty name="cpt['join_file']">

                            </notempty>
                            <a href="{$cpt['join_file']}">下载报名表</a>
                        </div>
                    </li>
                </foreach>

            </ul>
            <include file="Common/common_page" pageUrl="/competition/myJoinList?" />
</div>
<include file="Common/script" />
<script>
    // 取消报名
    $(document).on('click', '.cancel-join', function (e) {
        e.preventDefault();

        var id = $(this).data('id');

        $.ajax({
            url: '/competition/joinCancel',
            data: {
                join_id: id
            },
            type: 'POST',
            dataType: 'json',
            success: function (obj) {
                if (obj.code === 0) {
                    location.reload(true);
                } else {
                    eui.msg('操作失败');
                }
            },
            error: function () {
                eui.msg('系统出错');
            }
        });
    });
</script>
</body>
</html>